-module(slave).
-export([start/2, init/1]).
-export([init_worker/3]).

start(Node, Graph)->
    spawn_link(Node, slave, init, [Graph]).

init(Graph)->
    message_loop(Graph).

message_loop(Graph)->
    receive
	{run, Task} ->
	    run_task(Task,Graph),
	    message_loop(Graph);
	{die} ->ok
    end.

run_task(Task, Graph)->
    spawn(slave, init_worker, [Task, Graph, self()]).

init_worker(Task, Graph, Self)->
    Task(Graph, Self).
    
    
